import React, { useState } from 'react';
import { IFormItem, Itype } from '@/base-ui/form';
import http from '@/services/request';
import { Space, Button, Select } from 'antd';
import { Input, Tag } from 'antd';
import { CheckCircleOutlined, RightOutlined, UpOutlined, MinusCircleOutlined, SyncOutlined } from '@ant-design/icons';

const { Option } = Select;

const { Search } = Input;

export const commonFormColums: any = [
  {
    title: '批次编号',
    dataIndex: 'batchId',
    key: 'batchId',
    width: 100
  },
  {
    title: '批次品种',
    dataIndex: 'batchVariety',
    key: 'batchVariety',
    width: 100
  },
  {
    title: '供应商编号',
    dataIndex: 'supplierId',
    key: 'supplierId',
    width: 100
  },
  {
    title: '进苗时间',
    dataIndex: 'intakeTime',
    key: 'intakeTime',
    width: 100
  },
  {
    title: '鸡苗数量',
    dataIndex: 'quantity',
    key: 'quantity',
    width: 100
  },
  {
    title: '总金额',
    dataIndex: 'totalPrice',
    key: 'totalPrice',
    width: 100
  },
  {
    title: '鸡苗供应商名称',
    dataIndex: 'supplierName',
    key: 'supplierName',
    width: 100
  },
  {
    title: '养殖负责单位',
    dataIndex: 'breedUnit',
    key: 'breedUnit',
    width: 100
  },

  {
    title: '养殖计划负责人名称',
    dataIndex: 'responsibleName',
    key: 'responsibleName',
    width: 100
  },
  {
    title: '负责人联系电话',
    dataIndex: 'responsiblePhone',
    key: 'responsiblePhone',
    width: 100
  },
  {
    title: '计划完成情况',
    dataIndex: 'scheduleCompletion',
    key: 'scheduleCompletion',
    width: 100,
    render: (_: any, record: any) => {
      if (record.scheduleCompletion === 'success') {
        return (
          <Tag icon={<CheckCircleOutlined />} color="success">
            成功
          </Tag>
        )
      } else if (record.scheduleCompletion === 'cancel') {
        return (
          <Tag icon={<MinusCircleOutlined  />} color="default">
            终止
          </Tag>
        )
      } else {
        return (
          <Tag icon={<SyncOutlined spin  />} color="processing">
            进行中
          </Tag>
        )
      }
    }
  },
  {
    title: '预计出鸡平均体重',
    dataIndex: 'estimatedAverageWeight',
    key: 'estimatedAverageWeight',
    width: 100
  },
  {
    title: '预计出鸡合格率',
    dataIndex: 'estimatedPassRate',
    key: 'estimatedPassRate',
    width: 120
  },
  {
    title: '预计出鸡时间',
    dataIndex: 'estimatedSellTime',
    key: 'estimatedSellTime',
    width: 100
  },
  {
    title: '鸡苗平均体重',
    dataIndex: 'averageWeight',
    key: 'averageWeight',
    width: 100
  },
  {
    title: '备注',
    dataIndex: 'remark',
    key: 'remark',
    width: 150
  },
];
/* 搜索区域 */
export const PageSearchConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '订单编号',
    name: 'id',
    placeholder: '请输入订单编号'
  },
  {
    type: 'input' as Itype,
    label: '批次编号',
    name: 'batchId',
    placeholder: '请输入批次编号'
  },
  {
    type: 'datepicker' as Itype,
    label: '进苗时间',
    name: 'intakeTime',
    placeholder: '请输入进苗时间'
  },
  {
    type: 'datepicker' as Itype,
    label: '出鸡时间',
    name: 'estimatedSellTime',
    placeholder: '请输入预计出鸡时间'
  },
  {
    type: 'input' as Itype,
    label: '进苗数量',
    name: 'quantity',
    placeholder: '请输入进苗数量'
  },
  {
    type: 'input' as Itype,
    label: '总金额',
    name: 'totalPrice',
    placeholder: '请输入进苗总金额'
  },
  {
    type: 'input' as Itype,
    label: '鸡苗供应商',
    name: 'supplierName',
    placeholder: '请输入鸡苗供应商'
  },
  {
    type: 'input' as Itype,
    label: '鸡苗供应商编号',
    name: 'supplierId',
    placeholder: '请输入鸡苗供应商编号'
  },
  {
    type: 'input' as Itype,
    label: '养殖单位',
    name: 'breedUnit',
    placeholder: '请输入养殖单位'
  },
  {
    type: 'input' as Itype,
    label: '养殖负责人',
    name: 'responsibleName',
    placeholder: '请输入养殖负责人'
  },
  {
    type: 'input' as Itype,
    label: '养殖负责人电话',
    name: 'responsiblePhone',
    placeholder: '请输入养殖负责人电话'
  },
  {
    type: 'input' as Itype,
    label: '养殖完成情况',
    name: 'scheduleCompletion',
    placeholder: '请输入养殖完成情况'
  },
  {
    type: 'input' as Itype,
    label: '预计出鸡合格率',
    name: 'estimatedPassRate',
    placeholder: '请输入预计出鸡合格率'
  },
  {
    type: 'input' as Itype,
    label: '备注',
    name: 'remark',
    placeholder: '请输入备注'
  }
];

//高级检索
export const UseSearch = (props: any) => {
  return (
    <Space style={{ float: 'right' }}>
      {props.isMoreSearchShow ? (
        <Button
          type="link"
          size="large"
          onClick={() => {
            props.setisMoreSearchShow(false); props.setsearchMore(false);
          }}
        >
          收起
          <UpOutlined />
        </Button>
      ) : (
        <>
          <Button
            type="link"
            size="middle"
            onClick={() => {
              props.setisMoreSearchShow(true);props.setsearchMore(true);
            }}
          >
            高级检索
            <RightOutlined style={{ marginLeft: '1px' }} />
          </Button>
        </>
      )}
    </Space>
  );
};

export const SearchSelector = (props: any) => {
  const [searchid, setsearchid]: any = useState('batchId');
  return (
    <div
      style={{
        display: 'inline-block',
        width: '380px',
        marginBottom: 10,
        marginRight: 10,
        float: 'right'
      }}
    >
      <Select
        defaultValue={Options[0].label}
        style={{ width: 100 }}
        defaultActiveFirstOption
        onSelect={(value: string, option: any) => {
          setsearchid(option.key);
        }}
      >
        {Options.map((i) => (
          <Option value={i.label} key={i.value} children={null} />
        ))}
      </Select>
      <Search
        placeholder="请输入您要查的数据"
        onSearch={(e) => {
          if (e === '') {
            http.get('/feed/scheduleFarming/list/1/30').then((res) => {
              props.dataSource(res.data.records);
            });
            return;
          }
          switch (searchid) {
            case 'batchId': {
              http(`/feed/scheduleFarming/get/batchId/${e}`).then((res) => {
                props.dataSource(res.data);
              });
              break;
            }
            case 'supplierId': {
              http(`/feed/scheduleFarming/get/supplierId/${e}`).then((res) => {
                props.dataSource(res.data);
              });
              break;
            }
            case 'responsiblePhone': {
              http(`/feed/scheduleFarming/get/responsiblePhone/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            default: {
              break;
            }
          }
        }}
        style={{ width: '280px' }}
        enterButton
      />
    </div>
  );
};
export const Searchdow = () => {
  return;
};

const Options = [
  { label: '批次编号', value: 'batchId', onClick: (e: any) => {} },
  { label: '供应商编号', value: 'supplierId', onClick: (e: any) => {} },
  {
    label: '养殖负责人电话号码',
    value: 'responsiblePhone',
    onClick: (e: any) => {}
  }
];

/* 表格区域 */

//复选框的接口
export interface DataType {
  id: number;
  key: React.Key;
  name: string;
  age: number;
  address: string;
}
